const app = getApp()

Page({
    data: {
        loading: app.globalData.loading,
        activeIndex: 0,
        index: 0,
        currentTab: 0,
        swiperCurrent: 0,
        page: 1,
        refresh_top: !1,
        bkarr: [],
        adList: [],
        navBar: [],
        seller: []
    },
    onLoad(op) {
        app.setAppSystem(this), 
            app.userLogin(this),
            this.initData(op);
    },
    initData(op){
        let _this = this,
            c = _this.data.seller;
        app.hyy.request({
            url: "entry/wxapp/IndexData",
            data: {
                location: "023,023"
            },
            success(res) {
                var e = res.data.navbar;
                e.length <= 5 ? _this.setData({
                    height: 150
                }) : 5 < e.length && _this.setData({
                    height: 300
                });
                for (var a = [], n = 0, i = e.length; n < i; n += 10) a.push(e.slice(n, n + 10));
                _this.sellerChuli(res.data.tiezi);
                _this.initPlat(res.data.plate);
                _this.setData({
                    adList: res.data.ad,
                    navBar: a,
                });
                _this.setData({ loading: false });
            }
        });
    },
    onReady() { },
    updateUserInfo(t) {
        "getUserInfo:ok" == t.detail.errMsg && (this.setData({
            hydl: !1
        }), app.userLogin(this));
    },
    tabSelect(e) {
        this.setData({
            tabCur: e.currentTarget.dataset.id,
            scrollLeft: (e.currentTarget.dataset.id - 1) * 60
        })
    },
    phone(t) {
        var e = t.currentTarget.dataset.id;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    jumps(t) {
        var e = this,
            a = (t.currentTarget.dataset.name, t.currentTarget.dataset.appid),
            n = t.currentTarget.dataset.src,
            i = t.currentTarget.dataset.id,
            s = t.currentTarget.dataset.sjtype;
        var o = t.currentTarget.dataset.type;
        if (1 == o) {
            if ("../distribution/jrhhr" == n) return e.redinfo(), !1;
            if ("../store/store" == n) return wx.reLaunch({
                url: "../store/store"
            }), !1;
            if ("../fabu/fabu/fabu" == n) return wx.reLaunch({
                url: "../fabu/fabu/fabu"
            }), !1;
            if ("../user/user" == n) return wx.reLaunch({
                url: "../user/user"
            }), !1;
            if ("../type/type" == n) return wx.reLaunch({
                url: "../type/type"
            }), !1;
            wx.navigateTo({
                url: n,
                success(t) {
                    e.setData({
                        averdr: !0
                    });
                },
                fail(t) {},
                complete(t) {}
            });
        } else 2 == o ? wx.navigateTo({
            url: "../car/car?vr=" + i + "&sjtype=" + s,
            success(t) {},
            fail(t) {},
            complete(t) {}
        }) : 3 == o && wx.navigateToMiniProgram({
            appId: a,
            path: "",
            extraData: {
                foo: "bar"
            },
            success(t) {
                e.setData({
                    averdr: !0
                });
            }
        });
    },
    commend(t) {
        var e = this;
        t.currentTarget.dataset.index;
        var a = t.currentTarget.id,
            n = t.currentTarget.dataset.name;
        wx.setStorageSync("index", a),
            e.setData({
                index_class: !0,
                activeIndex: t.currentTarget.dataset.index,
                toView: "a" + (t.currentTarget.dataset.index - 1),
                bkname: n,
                refresh_top: !1,
                swipecurrent: t.currentTarget.id,
                seller: [],
                store1: [],
                yellow_list: [],
                pc: [],
                hdlist: [],
                page: 1,
                issljz: !1
            }), "1" == n && e.seller(), "2" == n && e.sjbk(), "3" == n && e.hybk(), "4" == n && e.sfcbk(),
            "5" == n && e.hdbmbk();
    },
    bkswiperChange(t) {
        var e = this;
        e.setData({
            refresh_top: !1,
            activeIndex: t.detail.current
        });
        var a = e.data.bkarr[t.detail.current];
        "最新信息" == a && e.seller(), "热门商家" == a && e.sjbk(), "黄页114" == a && e.hybk(),
            "顺风车" == a && e.sfcbk();
    },
    seller(t) {
        var o = this,
            e = (o.data.index_class, wx.getStorageSync("city"));
        app.hyy.request({
            url: "entry/wxapp/list2",
            cachetime: "0",
            data: {
                page: o.data.page,
                cityname: e
            },
            success(t) {
                o.sellerChuli(t.data);
            }
        });
    },
    sellerChuli(data) {
        let _this = this,
            t = {},
            c = this.data.seller,
            r = (wx.getStorageSync("index"), _this.data.page);
        t.data = data;
        if (0 == t.data.length) _this.setData({
            refresh_top: !0
        });
        else {
            _this.setData({
                refresh_top: !1,
                page: r + 1,
                issljz: !0
            }), c = c.concat(t.data), c = function(t) {
                for (var e = [], a = 0; a < t.length; a++) - 1 == e.indexOf(t[a]) && e.push(t[a]);
                return e;
            }(c);
        }
        if (t.data.length > 0) {
            for (var e in t.data) {
                var a = app.ormatDate(t.data[e].tz.sh_time);
                t.data[e].tz.img = t.data[e].tz.img.split(","),
                    t.data[e].tz.details = t.data[e].tz.details.replace("↵", " "),
                    4 < t.data[e].tz.img.length && (t.data[e].tz.img_length = Number(t.data[e].tz.img.length) - 4),
                    4 <= t.data[e].tz.img.length ? t.data[e].tz.img1 = t.data[e].tz.img.slice(0, 4) : t.data[e].tz.img1 = t.data[e].tz.img,
                    t.data[e].tz.time = a.slice(0, 16);
            }
            for (var n in c) {
                for (var i in c[n].label) c[n].label[i].number = (void 0, s = "rgb(" + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + ")", s);
                _this.setData({
                    seller: c
                });
            }
        }
    },
    onReachBottom() {
        var t = this,
            e = this.data.bkname;
        0 == this.data.refresh_top && this.data.issljz ? (console.log("上拉触底", e), "1" == e && t.seller(),
            "2" == e && t.sjbk(), "3" == e && t.hybk(), "4" == e && t.sfcbk(), "5" == e && t.hdbmbk()) : console.log("dobutno");
    },
    onShareAppMessage() {
        var t = this.data.System.zf_title;
        return "" == t && (t = this.data.System.pt_name), {
            title: t,
            path: "/hyy_city/pages/index/index",
            success(t) {},
            fail(t) {}
        };
    },
    initPlat(data) {
        let c = this,
            a = wx.getStorageSync("system");
        let e = [{
            type: "1",
            name: "最新信息"
        }];

        if (data.length > 0) {
            for (var i in data) {
                e.push(data[i]);
            }
        } else {

            "1" == a.is_sjrz && e.push({
                type: "2",
                name: "热门商家"
            }), "1" == a.is_pageopen && "1" == a.is_hyqx && e.push({
                type: "3",
                name: "黄页114"
            }), "1" == a.is_pcfw && "1" == a.is_pcqx && e.push({
                type: "4",
                name: "顺风车"
            }), "1" == a.is_hd && "1" == a.is_hdqx && e.push({
                type: "5",
                name: "活动报名"
            });
        }
        c.setData({
            bkname: e[0].type,
            bkarr: e
        });

    },
    sfcbk() {
        var a = this,
            t = (a.data.index_class, wx.getStorageSync("city")),
            n = (wx.getStorageSync("index"),
                a.data.page),
            i = a.data.pc;
        app.hyy.request({
            url: "entry/wxapp/CarList",
            cachetime: "0",
            data: {
                page: n,
                cityname: t
            },
            success(t) {
                if (0 == t.data.length ? a.setData({
                        refresh_top: !0
                    }) : (a.setData({
                        refresh_top: !1,
                        page: n + 1,
                        issljz: !0
                    }), i = i.concat(t.data)), 0 < t.data.length) {
                    for (var e in t.data) t.data[e].tz.time = app.ormatDate(t.data[e].tz.time).slice(5, 16),
                        t.data[e].tz.start_time1 = t.data[e].tz.start_time.slice(5, 10), t.data[e].tz.start_time2 = t.data[e].tz.start_time.slice(10, 17),
                        2 == t.data[e].tz.is_open ? (t.data[e].tz.class2 = "car3", t.data[e].tz.class3 = "car4",
                            t.data[e].tz.class4 = "car5") : (t.data[e].tz.class2 = "", t.data[e].tz.class3 = "",
                            t.data[e].tz.class4 = ""), "人找车" == t.data[e].tz.typename ? (t.data[e].tz.class = "color1",
                            t.data[e].tz.class1 = "car1") : "车找人" == t.data[e].tz.typename ? (t.data[e].tz.class = "color2",
                            t.data[e].tz.class1 = "car2") : "货找车" == t.data[e].tz.typename ? (t.data[e].tz.class = "color1",
                            t.data[e].tz.class1 = "car1") : "车找货" == t.data[e].tz.typename && (t.data[e].tz.class = "color2",
                            t.data[e].tz.class1 = "car2");
                    a.setData({
                        pc: i
                    });
                } else a.setData({
                    pc: i
                });
            }
        });
    },
    seeTeizi (t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../tiezi/detail?id=" + e
        });
    }

})